package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.TProduct;
import com.ruoyi.system.domain.TShipper;
import com.ruoyi.system.service.TShipperService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TShipper)表控制层
 *
 * @author makejava
 * @since 2025-01-01 20:37:34
 */
@RestController
@RequestMapping("tShipper")
public class TShipperController extends BaseController  {
    /**
     * 服务对象
     */
    @Resource
    private TShipperService tShipperService;

    /**
     * 分页查询
     *
     * @param tShipper 筛选条件
     * @return 查询结果
     */
    @GetMapping
    public TableDataInfo queryByPage(TShipper tShipper) {
        startPage();
        return getDataTable(this.tShipperService.queryByPage(tShipper));
    }

    /*
    * 获取供应商id查询产品
     */
    @GetMapping("/getSupplierByidProduct")
    public AjaxResult getSupplier(Integer id) {
        List<TProduct> result = this.tShipperService.getSupplierByidProduct(id);
        return AjaxResult.success(result);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TShipper> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tShipperService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tShipper 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TShipper> add(TShipper tShipper) {
        return ResponseEntity.ok(this.tShipperService.insert(tShipper));
    }

    /**
     * 编辑数据
     *
     * @param tShipper 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TShipper> edit(TShipper tShipper) {
        return ResponseEntity.ok(this.tShipperService.update(tShipper));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.tShipperService.deleteById(id));
    }

}

